package cn.otrue.patienthealthmanager.activity;

import java.util.HashMap;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.bean.TransferParameter;
import cn.otrue.patienthealthmanager.http.HttpCons;
import cn.otrue.patienthealthmanager.http.HttpServer;
import cn.otrue.patienthealthmanager.http.ServerHandler;
import cn.otrue.patienthealthmanager.utils.MyConst;

/**
 * 个人中心->意见反馈
 * 
 * @author G
 * 
 */
public class CenterFeedbackActivity extends BaseActivity {
	private TextView tv_title_title;
	private EditText et_yijian;
	private EditText et_lianxi;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_center_feedback);
		initView();

	}

	private Handler yijianHandler = new ServerHandler() {
		@Override
		public void onSuccess(Bundle data, String state, String msg) {

			if (state.equals("001")) {
				Toast.makeText(getApplicationContext(), msg, 0).show();

				finish();
			} else {
				Toast.makeText(getApplicationContext(), msg, 0).show();
			}
		}

		@Override
		public void onFail(Bundle data, String state) {
			if (state.equals(HttpCons.STATE_EXCEPTION)) {
				// 代表进入状态STATE_EXCEPTION 网络异常
				Toast.makeText(CenterFeedbackActivity.this, "网络异常,请稍后重试",
						Toast.LENGTH_SHORT).show();

			} else if (state.equals(HttpCons.STATE_FORMAT_ERROR)) {
				// 代表进入STATE_FORMAT_ERROR(不是Json)
			} else {
				// 代表进入STATE_ANALYTICAL_ERROR(Json解析错误)

			}
		}
	};
	private Button bt_yijian;

	private void yijian() {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("feedbackContent", et_yijian.getText().toString());
		map.put("feedbackContent", et_lianxi.getText().toString());
		TransferParameter parameter = new TransferParameter();
		parameter.setUsername(MyConst.getACCOUNT());
		parameter.setPassword("");
		parameter.setData(map);
		new HttpServer().post(HttpCons.insert_FeedbackInfo, parameter,
				yijianHandler);
	}

	private void initView() {
		initTitlBar();
		et_yijian = (EditText) findViewById(R.id.et_yijian);
		et_lianxi = (EditText) findViewById(R.id.et_lianxi);
		bt_yijian = (Button) findViewById(R.id.bt_yijian);
		bt_yijian.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				yijian();
				finish();
			}
		});
	}

	public void initTitlBar() {
		TextView tv_title_back = (TextView) findViewById(R.id.tv_title_back);
		TextView tv_title_title = (TextView) findViewById(R.id.tv_title_title);
		TextView tv_title_other = (TextView) findViewById(R.id.tv_title_other);

		tv_title_back.setVisibility(View.VISIBLE);
		tv_title_back.setOnClickListener(this);
		tv_title_title.setText(getString(R.string.idea_back));

	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.tv_title_back:
			finish();
			break;
		}
	}

}
